import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mziot/app/modules/home/controllers/home_controller.dart';
import 'package:mziot/app/modules/home/views/devices_list_view.dart';
import 'package:mziot/generated/assets.dart';
import 'package:mziot/generated/locales.g.dart';

class DevicesView extends GetView<HomeController> {
  DevicesView() {
    if (Get.arguments['groupId'] != null) {
      controller.groupId = Get.arguments['groupId'];
      controller.fetchGroupDevices();
    }
  }

  @override
  Widget build(BuildContext context) {
    final name = Get.arguments['name'];

    return WillPopScope(
      onWillPop: () {
        controller.groupId = null;
        return Future.value(true);
      },
      child: Scaffold(
        extendBodyBehindAppBar: true,
        appBar: AppBar(
          title: Text(LocaleKeys.home_group_title.trParams({'title': name})),
          backgroundColor: Colors.transparent,
        ),
        body: Stack(
          children: [
            Image.asset(
              Assets.imagesListBack,
              width: double.infinity,
              height: double.infinity,
              fit: BoxFit.cover,
            ),
            Container(
              child: DevicesListView(true),
            ),
          ],
        ),
      ),
    );
  }
}
